{extend name="adminblue/base" /}
{block name="resources"/}
<style>
	.data-loading-eject-layer {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10000;
		background: rgba(0, 0, 0, 0.4);
		display: none;
	}

	.prompt_information {
		width: 200px;
		height: 200px;
		position: relative;
		margin: auto;
		background: #fff;
		top: 30%;
		box-shadow: 0 0 6px -1px #bbb;
		border-radius: 20px;
	}

	.prompt_information .load-icon {
		width: 150px;
		height: 150px;
		line-height: 200px;
		margin: 0 auto;
		text-align: center;
	}

	.prompt_information .load-icon i {
		color: #bbb;
	}

	.prompt_information .information {
		height: 50px;
		text-align: center;
	}

	.progress_bar {
		width: 90%;
		margin: 5px auto;
		height: 5px;
		border: 1px solid #ddd;
	}

	.progress_bar .speed_of_progress {
		width: 3%;
		height: 5px;
		background: #0689e1;
	}

	.btn-common-delete:hover {
		color: #fff;
	}

	.btn-common-delete {
		background: #0059d6;
	}

	.mytable th {
		padding-left: 0px;
	}
</style>
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
{/block}
{block name="main"}
<table class="mytable select">
	<tr>
		<th >
			<button class="btn-common" id="UpdateFansList" href="javascript:;" style="float: left;">
				<i class="fa fa-refresh" aria-hidden="true"></i>
				<span>更新粉丝列表</span>
			</button>
		</th>
		<!--<th width="10%">-->
			<!--<input type="text" id='search_text' placeholder="请输入粉丝名称" class="input-common"/>-->
			<!--<button onclick="searchData()" value="搜索" class="btn-common">搜索</button>-->
		<!--</th>-->
		<th style="position: relative;">
			<span>下单时间：</span>
			<input type="text" id="startDate" class="input-common middle" placeholder="请选择开始日期"
				   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
			&nbsp;-&nbsp;
			<input type="text" id="endDate" placeholder="请选择结束日期" class="input-common middle"
				   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
			<button class="btn-common-white more-search"><i class="fa fa-chevron-down"></i></button>
			<button onclick="searchData()" class="btn-common">搜索</button>

			<!-- 更多搜索 -->
			<div class="more-search-container">
				<dl>
					<dt>粉丝名称：</dt>
					<dd>
						<input type="text" id='search_text' placeholder="请输入粉丝名称" class="input-common middle" />
					</dd>
				</dl>
				<dl>
					<dt>是否关注：</dt>
					<dd>
						<select name="is_sub" class="input-common middle" id="user_is_sub">
							<option value="">全部</option>
							<option value="1">已关注</option>
							<option value="0">取消关注</option>
						</select>
					</dd>
				</dl>
				<dl>
					<dt></dt>
					<dd>
						<button onclick="searchData()" class="btn-common">搜索</button>
					</dd>
				</dl>
			</div>
		</th>
	</tr>
</table>
<table class="table-class">
	<!--<colgroup>-->
		<!--<col style="width: 2%;">-->
		<!--<col style="width: 16%;">-->
		<!--<col style="width: 18%;">-->
		<!--<col style="width: 16%;">-->
		<!--<col style="width: 16%;">-->
		<!--<col style="width: 16%;">-->
		<!--<col style="width: 16%;">-->
	<!--</colgroup>-->
	<thead>
	<tr align="center">
		<th><i class="checkbox-common"><input type="checkbox" onclick="CheckAll(this)"></i></th>
		<th align="left">粉丝头像</th>
		<th align="left">粉丝名称</th>
		<th align="left">地址</th>
		<th>关注状态</th>
		<th>剩余积分 / 累计积分</th>
		<th>关注时间</th>
		<th align="left">备注</th>
		<th align="left">操作</th>
	</tr>
	</thead>
	<tbody></tbody>
</table>
<!-- 更新遮罩层 -->
<div class="data-loading-eject-layer">
	<div class="prompt_information">
		<div class="load-icon"><i class="fa fa-refresh fa-spin fa-5x fa-fw"></i></div>
		<div class="progress_bar">
			<div class="speed_of_progress"></div>
		</div>
		<p class="information">正在更新中</p>
	</div>
</div>

{/block}
{block name="script"}
<script type="text/javascript">
	function LoadingInfo(page_index) {
		var startDate = $("#startDate").val();
		var endDate = $("#endDate").val();
		var search_text = $("#search_text").val();
		var user_is_sub = $("#user_is_sub").val();
		var lookOrder = "{:__URL('ADMIN_MAIN/order/pushorderlist')}";
		$.ajax({
			type: "post",
			url: "{:__URL('ADMIN_MAIN/member/weixinfanslist')}",
			data: {
				"page_index": page_index,
				"page_size": $("#showNumber").val(),
				"search_text": search_text,
				"startDate": startDate,
				"endDate": endDate,
				"user_is_sub": user_is_sub,
			},
			success: function (data) {
				if (data["data"].length > 0) {
					$(".table-class tbody").empty();
					for (var i = 0; i < data["data"].length; i++) {
						var html = '';
						var is_subscribe = "";
						var sex = "";
						if (data["data"][i]["is_subscribe"] == 1) {
							is_subscribe = "已关注";
						} else {
							is_subscribe = "取消关注";
						}
						if (data["data"][i]["sex"] == 1) {
							sex = '男';
						} else {
							sex = '女';
						}
						var country = "";
						var province = "";
						var city = "";
						var district = "";
						if (data["data"][i]["country"] != "无") {
							country = data["data"][i]["country"];
						}
						if (data["data"][i]["province"] != "无") {
							province = data["data"][i]["province"];
						}
						if (data["data"][i]["city"] != "无") {
							city = data["data"][i]["city"];
						}
						if (data["data"][i]["district"] != "无") {
							district = data["data"][i]["district"];
						}

						var point = data["data"][i]["point"] == null ? '0' : data["data"][i]["point"];
						var member_sum_point = data["data"][i]["member_sum_point"] == null ? '0' : data["data"][i]["member_sum_point"];

						html += '<tr align="center">';
						html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="' + data["data"][i]["fans_id"] + '" ></i></td>';
						html += '<td align="left">';
						if (data["data"][i]["headimgurl"] == "") {
							html += '<img src="__STATIC__/images/default_user_portrait.gif" class="head-portrait" />';
						} else {
							html += '<img src="' + data["data"][i]["headimgurl"] + '" class="head-portrait" />';
						}
						html += '</td>';
						if (data["data"][i]["nickname_decode"] == null || "" == data["data"][i]["nickname_decode"]) {
							html += '<td align="left">--</td>';
						} else {
							html += '<td align="left">' + data["data"][i]["nickname_decode"] + '</td>';
						}
						html += '<td align="left">' + country + province + city + district + '</td>';

						html += '<td>' + is_subscribe + '</td>';
						html += '<td>' + point + ' / ' + member_sum_point + '</td>';
						html += '<td>' + timeStampTurnTime(data["data"][i]["subscribe_date"]) + '</td>';
						html += '<td align="left">' + data["data"][i]["memo"] + '</td>';
						html += '<td align="left"><a href="'+lookOrder+'&openid='+data["data"][i]['openid']+'">查看订单</a></td>';
						html += '</tr>';
						$(".table-class tbody").append(html);
					}
				} else {
					var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
					$(".table-class tbody").html(html);
				}
				initPageData(data["page_count"], data['data'].length, data['total_count']);
				$("#pageNumber").html(pagenumShow(jumpNumber, $("#page_count").val(), {$pageshow}));
			}
		});
	}

	//全选
	function CheckAll(event) {
		var checked = event.checked;
		$("#productTbody input[type = 'checkbox']").prop("checked", checked);
		if (checked) $(".table-class tbody input[type = 'checkbox']").parent().addClass("selected");
		else $(".table-class tbody input[type = 'checkbox']").parent().removeClass("selected");
	}

	function searchData() {
		LoadingInfo(1);
	}

	var page_count = 0;
	var pageIndex = 0;
	$("#UpdateFansList").click(function () {
		$.ajax({
			type: "post",
			url: "{:__URL('ADMIN_MAIN/member/updateWchatFansList')}",
			data: {"page_index": pageIndex},
			beforeSend: function () {
				$(".data-loading-eject-layer").fadeIn();
			},
			success: function (data) {
				if (pageIndex == 0) {
					page_count = data["page_count"];
				}
				if (data["errcode"] != undefined && data["errcode"] < 0) {
					$(".data-loading-eject-layer").fadeOut();
					showTip(data['errorMsg'], 'error');
				} else if (data["errcode"] == 0) {
					if (pageIndex <= page_count) {
						pageIndex = parseInt(pageIndex) + 1;
						$("#UpdateFansList").click();
						if (pageIndex <= page_count) {
							var speed_of_progress = pageIndex / page_count * 100;
							$(".speed_of_progress").width(speed_of_progress + '%');
							$(".information").text('当前已完成' + pageIndex + '/' + page_count);
						}
					} else {
						$(".data-loading-eject-layer").fadeOut();
						showTip(data['message'], 'success');
						location.href = "{:__URL('ADMIN_MAIN/member/weixinfanslist')}";
					}
				}
			}
		});
	})

	// 点击显示更多搜索
	$(".more-search").on("click", function (e) {
		$(".more-search-container").slideToggle();
		$(document).one("click", function () {
			$(".more-search-container").slideUp();
		});
		e.stopPropagation();
	})

	$(".more-search-container").on("click", function (e) {
		e.stopPropagation();
	});
</script>
{/block}